﻿Imports Microsoft.Xna.Framework
Imports Runa.Graphics.Effects

Namespace Global.Runa.UI.Metadata

    Public Class EffectConverter
        Inherits TypeConverter

        Public Sub New(g As Game)
            MyBase.New(g)
        End Sub

        Public Overrides Function ConvertFromInvariantString(text As String) As Object
            Return Me.GetEffects()(text)
        End Function

        Public Overrides Function ConvertFromString(text As String) As Object
            Return ConvertFromInvariantString(text)
        End Function

        Public Overrides Function ConvertToInvariantString(value As Object) As String
            If TypeOf value Is EffectBase Then
                Return Me.GetEffects().First(Function(item) item.Value Is CType(value, EffectBase)).Key
            Else
                Return ""
            End If
        End Function

        Public Overrides Function ConvertToString(value As Object) As String
            Return ConvertToInvariantString(value)
        End Function

        Private Function GetEffects() As Dictionary(Of String, EffectBase)
            Return CType(Me.Game, Runa.Core.Services.IGameParameterService).Effects
        End Function

    End Class

End Namespace